<?php

namespace App\Http\Controllers;

use App\Common\Sql;
use Illuminate\Support\Facades\DB;

class GoldMall extends Base
{
    public function logic()
    {
        $row = Sql::select('t_gold_mall_conf', [['status', 1]]);
        if (count($row) == 0) {
            return $this->returnError(1, '没有商品');
        } else {
            $goods_arr = array();
            foreach ($row as $g) {
                $arr['id']       = (int)$g['id'];
                $arr['name']     = $g['name'];
                $arr['hot_flag'] = (int)$g['hot_flag'];
                $arr['price']    = (int)$g['price'];
                $arr['gold']     = (int)$g['gold'];
                $arr['give_num'] = 0;
                $goods_arr[]     = $arr;
            }
            return $this->returnData(array("gold_mall" => $goods_arr));
        }
    }


    public function ticketMall()
    {
        return $this->returnData([
                'ticket_mall' =>
                    DB::table('t_ticket_mall_conf')->where('status', 1)->get()->map(function ($value) {
                        $value->num = $value->ticket;
                        unset($value->ticket);
                        return $value;
                    })
            ]
        );
    }

}

